----------------------------
Sun Gear OXP
----------------------------

Author: Stranger
This OXP is inspired by Distant Suns OXP (author of original work Wildblood).
This OXP is released under the Creative Commons Attribution - Non-Commercial - Share Alike 3.0 license.
You are free to use and distribute this OXP on non-commercial basis. 
Rebundling of this OXP within another distribution is permitted as long as it is unchanged.
Any mods/derivatives of this OXP must be distributed under another names.
The license information (either as this file or merged into a larger one) must be included in the OXP.

Features:

Distribution of sun colors rebalanced in accordance with real astronomical data. Despite red dwarves being most common class in Galaxy stellar population most part of known exoplanets belongs to yellow Sun-like G-stars and orange K-stars (https://en.wikipedia.org/wiki/List_of_exoplanetary_host_stars). It may reflect observation bias of course but planets of yellow Sun-like stars seems to be more hospitable for colonization.
More detailed system of spectral classes - 28 spectral subclasses from M3.5V to F6V (Wildblood's spectra covers only 6 base classes) and 56 unique spectral signatures (two steps for subclass).
Spectral classes B and A completely removed from Ooniverse. Hottest bound of main sequence is limited to F6 spectral subclass. Bluish-white hot stars are too short-lived to maintain advanced ecosystems in real worlds and bit ugly in Ooniverse :-(
Spectral class M restricted to M3 stars to adopt more realistic star models. Red dwarves in real world has too low luminosities to model habitable zones in Oolite.
Sun radius is a function of spectral class. Sun radius and luminosity function vs spectral class based on real astronomical data.
Large suns and solar systems implemented - sun radii are in range 3600001120000 km (smoothed distribution), main planet orbit radii are approx. 2040 times of default value.
Spectral class of sun and main planet radius are correlated values - large main planets in white and yellow hot star systems, small main planets in systems of red and orange dwarves.
Distance from sun to main planet is a function of sun luminosity.
Habitable zones simulated. Main planets are located near Standard Insolation Level with random distance bias  5%. Large main planets in systems of white and yellow stars has more warm climate as compared with small main planets in systems of orange and red dwarves not due to more hot sun per se but due to more dense atmospheres providing more evident greenhouse effect.
Corona flare is controlled dynamically via script. Most of time sun of system is in quiet state (corona_flare random value in range 0.10.2), but sometimes solar flares occurs and corona_flare rises randomly up to 0.5 (yes, I know, in reality it is NOT linear correlation between solar corona size and solar flares!). As a rule flare frequency increases from yellow to red stars. Peculiar suns with "solar activity" in system description has more frequent flares with higher magnitudes (corona_flare rises up to 1.0 in case of "deadly solar activity").
Wildblood's spectroscope script was rewritten to adopt RGB color model. Sun radius is used to determine sun spectral class instead named color.
Solar wind model is implemented. Solar wind flux is a function of solar radius and corona flare, distance to sun and ship speed.
Solar wind allows to refuel ship without sunskimming (in some cases refuelling is possible en route from witchpoint to main planet).
Magnetospheres of celestial bodies are simulated. Solar wind density is drop to zero level near planets and moons. Upper boundary of magnetosphere is equal to upper boundary of gravity well (green/yellow horizon).

AstroLibrary

AstroLibrary is a library, providing astronomic (oostronomic may be?) functions to calculate sun spectrum, main planet temperature (used in Planetary Systems OXP to set planet texture), main planet orbital period &  planet and moon parameters (used in Planetary Systems OXP to display on special info screen), solar wind density (used in Hard Way OXP to collect fuel) etc.


Advanced System Data MFD

Advanced System Data MFD provides custom system info on two pages.

Sun Data info page displays:

Sun catalog number (galaxy sector and system ID)
Sun spectral class
Sun radius
Sun mass
Sun luminosity
Solar activity
Main planet period in days
Sun distance
Solar wind flux

Planetary System Data info page provides list of additional planets in solar system. It displays only planet orbit radii in OU and planet class:

Dwarf terra  planet like Pluto or Ceres
Miniterra  planet like Mercury
Subterra  planet like Mars
Terra  planet like Earth or Venus
Superterra  planet like hmm, we have no such example in our Solar System. Gliese 667 Cc maybe?
Ice giant  planet like Uranus or Neptune
Gas giant  planet like Jupiter or Saturn

System Data Sheet

Advanced system info also available in docked state using F4 screen. Select System Data Sheet option to view info:

Sun spectral class
Sun radius
Sun mass
Sun luminosity
Main planet period in days
List of system planets

System Data Sheet is available even if your ship has no ASC, but this service is provided only on GalCop main stations.

Dependencies

Sun Gear OXP requires Habitable Main Planets OXP installed because sun population is generated using recalibrated main planet radii, not vanilla ones.

Compatibility notes

Vast solar systems can cause problems in intra-system missions such as search and rescue operations or in-system taxi service. So you need additional OXPs to overcome these difficulties. Some OXPs uses absolute coordinates to populate systems with custom objects, so you may find such objects placed too close to large suns for example.
Refueling by sun-skimming is really challenging task in case of large suns (you have no enough time to leave more wide overheat zone). This is not the case if you are using fuel collection from solar wind, but this option is realized for player ship only, so pre-scripted AI sun-skimming activity will be suicidal behavior pattern.

Disclaimer:

Sun Gear is NOT simulation of real solar systems. It uses some relative values from real astronomy, scaled to fit into Oolite game world.
Don't try to use this software for real interstellar navigation!

Credits:

Wildblood - Distant Suns OXP/OXZ: initial concept of custom sun population & spectroscope script.
Tch - Tch_Russian_Systems OXP: idea of using RGB model for sun color.
Rustem - Distant Stars OXP/OXZ: idea of dynamic coronae.
Damocles Edge, phkb and another_commander - for detecting OXP incompatibility with DH ANC OXP, formulation of issue with HSB colors and invaluable help to solve this issue.
Dybal, Milo and Cholmondely - valuable feedback for improving this OXP.

---------------------
Installation and use:
---------------------

To use, simply place the Sun Gear OXP into your "AddOns" folder or download OXZ from OXZ manager.
To call Sun Data MFD page lock Advanced Space Compass onto sun and list MFD modes.
To call Planetary System Data MFD page "Stellar Data" lock Advanced Space Compass onto any planet or moon and list MFD modes.
Advanced System Data MFD is not purchasable upgrade. It is expanded functionality of ASC, so upgrade your basic astrocompass to ASC is the only necessary condition to have access to Advanced System Data.
To use solar wind feature for fuel collection you need Hard Way OXP to be installed.

This package minimum requirement is Oolite 1.82. Integer-valued distance format in early versions of Oolite before 1.80 and graphical glitch with distant objects in Oolite 1.80 prevents using of this package in pre-1.82 Oolite versions.

-----------
Change Log:
-----------

12.07.2026 - Version 4.6.0	Improved script solar_system_data.js to fix issue with excessive event handlers. Two shipWillDockWithStation event handlers merged.
				Fixed issue with list of system planets on System Data Sheet. List of system planets now stored in oolite-save and displayed correctly after loading saved game.
03.12.2022 - Version 4.5.2	System Data Sheet on F4 screen now declared as Informational instead Ambience 
01.12.2022 - Version 4.5.1	Code improved to activate System Data Sheet on F4 screen after start-up.
01.12.2022 - Version 4.5.0	Added System Data Sheet on F4 screen.
07.07.2020 - Version 4.4.0	Fixed error in log file generated by SolarSystemData script in case of misjump.
03.07.2020 - Version 4.3.2	Fixed missed parenthesis in manifest.plist preventing download OZX via OXZ manager.
03.07.2020 - Version 4.3.1	Uploaded repeatedly to override problem with downloading version 4.3.0.
02.07.2020 - Version 4.3.0	Redefined sun database based on redefined Habitable Main planets radii.
				Spectral class range now includes suns from F6V to M3.5V.
				AstroLibrary improved again to display added spectral classes.
				Improved script to display info on Planetary System Data MFD page based on redefined planet classification.
23.04.2019 - Version 4.2.0	Tweaked runaway greenhouse trigger in PlanetEngine.
17.04.2019 - Version 4.1.0	Improved function for simple calculation of main planet temperature.
				(still has some discrepancy with result of more complex calculation of planet temperature in PlanetEngine)
06.02.2019 - Version 4.0.0	Sun colors redefined in RGB model.
				Distant Suns and Distant Stares declared as conflicting OXPs in manifest.plist.
04.02.2019 - Version 3.9.0	Fixed error in variable name, preventing display of sun spectral class on F7 System Info page.
02.02.2019 - Version 3.8.0	PlanetEngine improved again - less one empirical quotient, less one IF-THEN-ELSE construction, almost the same result.
02.02.2019 - Version 3.7.0	Improved AstroLibrary functions for calculation of planet atmospheres in PlanetEngine.
31.01.2019 - Version 3.6.1	Converted onto OXZ
04.12.2018 - Version 3.6	More detailed spectral class info displayed (such as G2V or G2.5V instead just G2V)
				Some tweaks in names of variables.
14.09.2018 - Version 3.5	Tweaked sun parameters to synchronize with updated Habitable Main Planets.
				manifest.plist added.
25.08.2018 - Version 3.4	Fixed critical error in calculation of main planet temperature in remote systems.
18.08.2018 - Version 3.3	Tweaked sun parameters for agricultural planets with TL < 4.
17.08.2018 - Version 3.2	Suns of F8V, F9V and M2V spectral class added.
				AstroLibrary improved to display added spectral classes.
				Function main planet size vs sun size recalibrated.
				All main planets centered to Standard Insolation Level with random distance bias  5%.
				Greenhouse effect is added to calculation of main planet temperature.
12.08.2018 - Version 3.1	Main planet temperature data removed from Sun Data MFD page.
12.06.2018 - Version 3.0	Calculation of additional planet parameters added to AstroLibrary.
				Info pages Sun Data and Planetary System Data displayed on MFD.
				Info screen is removed as obsolete and unrecommended method. 
19.05.2018 - Version 2.9	Minor tweak in planet classification displayed on planet info page.
13.05.2018 - Version 2.8	AstroLibrary code refactored to satisfy JavaScript strict mode.
28.04.2017 - Version 2.7	AstroLibrary functions improved.
				Sun temperature and mass are calculated functions of sun radius, not fixed predefined values.
27.04.2017 - Version 2.6	Sun parameters upgraded to fit more resent astronomical data.
				Less yellow G-stars, more orange K-stars in star population.
				Sun radii distribution smoothed, every sun on chart has unique radius and luminosity.
				Smoothed function of main planet orbit radius vs sun luminosity with pseudo-random shift provides more accurate matching to habitable zone.
				All 99 Famous Planets (extended set) orbital parameters verified and tuned to match planet texture vs calculated temperature.
				All 8 planetinfo.plist merged onto one planetinfo.plist. Package reassembled onto more simple structure.
				Distance from main planet to sun is redefined in absolute value sun_distance.
				Distance in planet radii (sun_distance_modifier) is abandoned as obsolete method.
				AstroLibrary functions rewritten to adopt new smoothed sun radii feature.
22.10.2016 - Version 2.5	Dynamic solar coronae implemented.
				Solar wind density recalibrated to new model.
				Sun Coronae dictionaries deleted.
				Fixed error in calculation of sun luminosity, reduced to standard Sun candle (used to display Sun Data).
				corona_flare is displayed in Sun Data as human-friendly Sun Activity index in range from 1.00 to 10.00.
20.07.2016 - Version 2.4	Public release of Sun Gear with updated code.
09.07.2016 - Version 2.3	Planetary System Data page code rewritten to adopt expanded planet set from Planetary Systems OXP
				(some info for internal testing added).
25.12.2015 - Version 2.2	Hull temperature info removed from F7 screen.
18.11.2015 - Version 2.1	Sun scale boosted up to 10x.
				M1V star spectral class added.
				Calculation of main planet temperature and ship hull temperature added to AstroLibrary functions.
				AstroLibrary functions generates solar radius, mass and luminosity values with some pseudorandom component.
				Sun info screen divided onto 2 pages - Stellar Data (sun info) and Planetary System Data (planet info).
11.06.2015 - Version 2.0	New sun scale implemented. Sun radii and main planet distances scaled up to 4x.
				Fine tuning of arctic Famous Planets systems - more cold suns for Qutiri, Beusrior, Edorte etc (8 systems readjsted)
27.11.2014 - Version 1.9	Sun database is completely rewritten again :-)
				Local sun_distance_modifier values are restored to fix radii of habit zones.
21.10.2014 - Version 1.8	16 Famous Planets sun radii readjusted to fix conflict with descriptions and texture appearance.
				Solar wind flow check condition switched to Green status.	
22.09.2014 - Version 1.7	Sun database is completely rewritten again. Correlation sun radius vs planet radius refined.
				sun_distance_modifier is fixed to 60 main planet radii for all systems. 
15.09.2014 - Version 1.6	Sun database is completely rewritten to adopt new correlation sun radius vs planet radius.
				Sun coronae also recalculated and rewritten.
28.06.2014 - Version 1.5	Main planet period calculation refined.
				A bit randomness to main planet period added.
				Main planet period info added to Stellar Data screen.
27.06.2014 - Version 1.4	AstroLibrary improved with database of main planet orbital periods.
24.06.2014 - Version 1.3	Spectral class F stars completely removed from database.
				Distribution of other suns readjusted.
				Parameter sun_distance_modifier is readjusted.
				Sun color curve readjusted to Oolite 1.80.
19.05.2014 - Version 1.2	AstroLibrary improved to scan planets, created by Planetary Systems OXP.
14.05.2014 - Version 1.1	Code rewritten to use AstroLibrary global functions.
12.03.2014 - Version 1.0	Fixed bug in solar_wind.js (incorrect test for interstellar space replaced).
20.01.2014 - Version 0.9	Fixed bug in solar_wind.js (overflow of fuel collect counter in close proximity of sun).
07.12.2013 - Version 0.8	Some code refining (not reflected in game functionality).
30.11.2013 - Version 0.7	Corona parameters are completely rewritten.
				Unified version index is implemented (old Sun Coronae Chart 1 version 0.3.oxp, for example, replaced to simple Sun Coronae Chart 1.oxp).
19.11.2013 - Version 0.6	Magnetospheres of celestial bodies are simulated.
				Garbage piece of code removed from sun_info.js (unused variables in startUp function).
				Calculation of solar wind critical density is refined.
16.11.2013 - Version 0.5	Minor bug in sun_info.js fixed (corona_flare value output fixed to 2 digits).
				Old Wildblood licence text removed. 
15.11.2013 - Version 0.4	Nested sun spectra scripts replaced to single script for all 8 charts.
				Solar wind model and new scheme of refuelling implemented. Sun info screen is added.
18.07.2013 - Version 0.3	Wildblood Sun Debugger is removed.
				Brief info for Russian gamers is included.
02.03.2013 - Version 0.2	All 8 Sun Spectra planetinfo.plist are completely rewritten to adopt improved sun model.
				Spectral class M is restricted to M0 stars, M1M5 stars removed from database.
				Some improvement in color model.
				All 8 Sun Coronae planetinfo.plists are edited - a bit tweak of Wildblood's coronae.
23.02.2013 - Version 0.1	Initial release.